<?php
namespace app\admin\model;
use think\Model;

class Type extends Model
{
	protected $autoWriteTimestamp = true;

	public function add($data)
	{
		$data['status'] = 1;
		$result = $this->save($data);
		return $data;
	}

	// 获取以及类型
	public function getNormalFirstType()
	{
		$data = [
			'status' => 1,
			'parent_id' => 0,
		];

		$order = [
			'id' => 'asc',
		];

		return $this->where($data)->order($order)->select();
	}

	public function getChildType()
	{
		$data = [
			'status' => 1,
			'parent_id' => ['neq',0],
		];

		$order = [
			'listorder' => 'desc',
			'id' => 'desc',
		];

		return $this->where($data)->order($order)->select();
	}

	public function getFirstTypes($parent_id = 0)
	{
		$data = [
			'parent_id' => $parent_id,
			'status' => ['neq',-1],
		];

		$order = [
			'listorder' => 'desc',
			'id' => 'desc',
		];

		return $this->where($data)->order($order)->paginate(3);
	}
}
